package fms.models;
 
import java.util.List;
 
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import fms.classes.Form9_1;
 
 
public class Form9_1DAO {
 
    private SqlSessionFactory sqlSessionFactory;
 
    public Form9_1DAO(){
    	try{
    		sqlSessionFactory = MyBatisSqlConnection.getSqlSessionFactory();
    	}catch(Exception e) {
    		System.out.println("failed to get sqlSessionFactory");
    	}
    }
 
    /**Returns the list of all Form9_1 instances from the database*/
    @SuppressWarnings("unchecked")
    public List<Form9_1> selectAll(){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            List<Form9_1> list = session.selectList("Form9_1.getAll");
            return list;
        } finally {
            session.close();
        }
    }
 
    /**Returns a Form9_1 instance from the database*/
    public Form9_1 selectById(int payroll_no){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            Form9_1 form9_1 = (Form9_1) session.selectOne("Form9_1.getById", payroll_no);
            return form9_1;
        } finally {
            session.close();
        }
    }
 
    /**Updates an instance of Form9_1 in the database*/
    public void update(Form9_1 form9_1){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.update("Form9_1.update", form9_1);
            session.commit();
        } finally {
            session.close();
        }
    }
 
    /** Insert an instance of Form9_1 into the database*/
    public void insert(Form9_1 form9_1){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.insert("Form9_1.insert", form9_1);
            session.commit();
        } finally {
            session.close();
        }
    }
 
    /** Delete an instance of Form9_1 from the database*/
    public void delete(int payroll_no){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.delete("Form9_1.deleteById", payroll_no);
            session.commit();
        } finally {
            session.close();
        }
    }
}